﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace MinimalistFoodStreet.BackEnd.Infrastructure.EFCore;

public partial class MinimalistFoodStreetContext : DbContext
{
    public MinimalistFoodStreetContext(DbContextOptions<MinimalistFoodStreetContext> options)
        : base(options)
    {
    }

    public virtual DbSet<Account> Accounts { get; set; }

    public virtual DbSet<ActionLog> ActionLogs { get; set; }

    public virtual DbSet<Administrator> Administrators { get; set; }

    public virtual DbSet<Businesss> Businessses { get; set; }

    public virtual DbSet<Chart> Charts { get; set; }

    public virtual DbSet<Collection> Collections { get; set; }

    public virtual DbSet<Comment> Comments { get; set; }

    public virtual DbSet<CommentLike> CommentLikes { get; set; }

    public virtual DbSet<CommentResource> CommentResources { get; set; }

    public virtual DbSet<Dictionary> Dictionarys { get; set; }

    public virtual DbSet<DictionaryType> DictionaryTypes { get; set; }

    public virtual DbSet<ErrorLog> ErrorLogs { get; set; }

    public virtual DbSet<Good> Goods { get; set; }

    public virtual DbSet<History> Historys { get; set; }

    public virtual DbSet<Info> Infos { get; set; }

    public virtual DbSet<LoginLog> LoginLogs { get; set; }

    public virtual DbSet<Order> Orders { get; set; }

    public virtual DbSet<OrderDetail> OrderDetails { get; set; }

    public virtual DbSet<Promotion> Promotions { get; set; }

    public virtual DbSet<SearchRecord> SearchRecords { get; set; }

    public virtual DbSet<Supplier> Suppliers { get; set; }

    public virtual DbSet<Varify> Varifys { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .UseCollation("utf8mb4_unicode_ci")
            .HasCharSet("utf8mb4");

        modelBuilder.Entity<Account>(entity =>
        {
            entity.HasKey(e => e.AId).HasName("PRIMARY");

            entity.ToTable("accounts", tb => tb.HasComment("账号表"));

            entity.HasIndex(e => e.AAccount, "a_account").IsUnique();

            entity.HasIndex(e => e.AEmail, "a_email").IsUnique();

            entity.HasIndex(e => e.APhone, "a_phone").IsUnique();

            entity.Property(e => e.AId)
                .HasComment("r,u,d-编号")
                .HasColumnName("a_id");
            entity.Property(e => e.AAccount)
                .HasMaxLength(32)
                .HasComment("r-账户")
                .HasColumnName("a_account");
            entity.Property(e => e.AAvatar)
                .HasMaxLength(42)
                .HasComment("r-头像")
                .HasColumnName("a_avatar");
            entity.Property(e => e.ACreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("a_create_time");
            entity.Property(e => e.AEmail)
                .HasMaxLength(256)
                .HasComment("r-邮箱")
                .HasColumnName("a_email");
            entity.Property(e => e.AEndpoint)
                .HasComment("r-哪个端的账号(管理端，供应商端，商家端)")
                .HasColumnType("enum('administrators','suppliers','business')")
                .HasColumnName("a_endpoint");
            entity.Property(e => e.AIsActive)
                .HasComment("r-是否激活")
                .HasColumnName("a_is_active");
            entity.Property(e => e.AIsBan)
                .HasComment("r-是否禁用")
                .HasColumnName("a_is_ban");
            entity.Property(e => e.AName)
                .HasMaxLength(32)
                .HasComment("r-名称默认采用账号")
                .HasColumnName("a_name");
            entity.Property(e => e.APassword)
                .HasMaxLength(32)
                .HasComment("密码")
                .HasColumnName("a_password");
            entity.Property(e => e.APhone)
                .HasMaxLength(11)
                .IsFixedLength()
                .HasComment("r-电话")
                .HasColumnName("a_phone");
            entity.Property(e => e.ASalt)
                .HasMaxLength(32)
                .HasComment("盐值")
                .HasColumnName("a_salt");
            entity.Property(e => e.AUpdateTime)
                .ValueGeneratedOnAddOrUpdate()
                .HasComment("r-修改时间")
                .HasColumnType("datetime")
                .HasColumnName("a_update_time");
        });

        modelBuilder.Entity<ActionLog>(entity =>
        {
            entity.HasKey(e => e.AlId).HasName("PRIMARY");

            entity.ToTable("action_logs", tb => tb.HasComment("行为日志表"));

            entity.HasIndex(e => e.AlAccountId, "al_account_id");

            entity.Property(e => e.AlId)
                .HasComment("r,u,d-编号")
                .HasColumnName("al_id");
            entity.Property(e => e.AlAccountId)
                .HasComment("r-请求人")
                .HasColumnName("al_account_id");
            entity.Property(e => e.AlAffectedRows)
                .HasComment("r-受影响行数")
                .HasColumnName("al_affected_rows");
            entity.Property(e => e.AlCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("al_create_time");
            entity.Property(e => e.AlIp)
                .HasMaxLength(20)
                .HasComment("r-ip地址")
                .HasColumnName("al_ip");
            entity.Property(e => e.AlMessage)
                .HasMaxLength(200)
                .HasComment("r-消息")
                .HasColumnName("al_message");
            entity.Property(e => e.AlRequestMethod)
                .HasMaxLength(10)
                .HasComment("r-请求方法")
                .HasColumnName("al_request_method");
            entity.Property(e => e.AlRequestParams)
                .HasComment("r-请求参数(json)")
                .HasColumnType("text")
                .HasColumnName("al_request_params");
            entity.Property(e => e.AlRequestUrl)
                .HasMaxLength(200)
                .HasComment("r-请求地址")
                .HasColumnName("al_request_url");

            entity.HasOne(d => d.AlAccount).WithMany(p => p.ActionLogs)
                .HasForeignKey(d => d.AlAccountId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("action_logs_ibfk_1");
        });

        modelBuilder.Entity<Administrator>(entity =>
        {
            entity.HasKey(e => e.AId).HasName("PRIMARY");

            entity.ToTable("administrators", tb => tb.HasComment("管理员表"));

            entity.HasIndex(e => e.AAccountId, "a_account_id");

            entity.Property(e => e.AId)
                .HasComment("r,u,d-编号")
                .HasColumnName("a_id");
            entity.Property(e => e.AAccountId)
                .HasComment("c,r,u-账号编号")
                .HasColumnName("a_account_id");
            entity.Property(e => e.AAge)
                .HasComment("c,r,u-年龄")
                .HasColumnName("a_age");
            entity.Property(e => e.ACreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("a_create_time");
            entity.Property(e => e.AName)
                .HasMaxLength(32)
                .HasComment("c,r,u-姓名")
                .HasColumnName("a_name");
            entity.Property(e => e.AUpdateTime)
                .ValueGeneratedOnAddOrUpdate()
                .HasComment("r-修改时间")
                .HasColumnType("datetime")
                .HasColumnName("a_update_time");

            entity.HasOne(d => d.AAccount).WithMany(p => p.Administrators)
                .HasForeignKey(d => d.AAccountId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("administrators_ibfk_1");
        });

        modelBuilder.Entity<Businesss>(entity =>
        {
            entity.HasKey(e => e.BId).HasName("PRIMARY");

            entity.ToTable("businesss", tb => tb.HasComment("商家表"));

            entity.HasIndex(e => e.BAccountId, "b_account_id");

            entity.Property(e => e.BId)
                .HasComment("r,u,d-编号")
                .HasColumnName("b_id");
            entity.Property(e => e.BAccountId)
                .HasComment("c,r,u-账号编号")
                .HasColumnName("b_account_id");
            entity.Property(e => e.BCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("b_create_time");
            entity.Property(e => e.BManagerName)
                .HasMaxLength(32)
                .HasComment("c,r,u-店主姓名")
                .HasColumnName("b_manager_name");
            entity.Property(e => e.BName)
                .HasMaxLength(32)
                .HasComment("c,r,u-店铺名称")
                .HasColumnName("b_name");
            entity.Property(e => e.BOpenId)
                .HasMaxLength(50)
                .HasComment("c,r,u-微信ID")
                .HasColumnName("b_open_id");
            entity.Property(e => e.BUpdateTime)
                .ValueGeneratedOnAddOrUpdate()
                .HasComment("r-修改时间")
                .HasColumnType("datetime")
                .HasColumnName("b_update_time");

            entity.HasOne(d => d.BAccount).WithMany(p => p.Businessses)
                .HasForeignKey(d => d.BAccountId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("businesss_ibfk_1");
        });

        modelBuilder.Entity<Chart>(entity =>
        {
            entity.HasKey(e => e.CId).HasName("PRIMARY");

            entity.ToTable("charts", tb => tb.HasComment("购物车表"));

            entity.HasIndex(e => e.CBusinessId, "c_business_id");

            entity.HasIndex(e => e.CGoodId, "c_good_id");

            entity.Property(e => e.CId)
                .HasComment("r,d-编号")
                .HasColumnName("c_id");
            entity.Property(e => e.CBusinessId)
                .HasComment("c,r-商家编号")
                .HasColumnName("c_business_id");
            entity.Property(e => e.CGoodCount)
                .HasComment("c,r,u-商品数量")
                .HasColumnName("c_good_count");
            entity.Property(e => e.CGoodId)
                .HasComment("c,r-商品编号")
                .HasColumnName("c_good_id");

            entity.HasOne(d => d.CBusiness).WithMany(p => p.Charts)
                .HasForeignKey(d => d.CBusinessId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("charts_ibfk_2");

            entity.HasOne(d => d.CGood).WithMany(p => p.Charts)
                .HasForeignKey(d => d.CGoodId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("charts_ibfk_1");
        });

        modelBuilder.Entity<Collection>(entity =>
        {
            entity.HasKey(e => e.CId).HasName("PRIMARY");

            entity.ToTable("collections", tb => tb.HasComment("收藏表"));

            entity.HasIndex(e => e.CBusinessId, "c_business_id");

            entity.HasIndex(e => e.CGoodId, "c_good_id");

            entity.Property(e => e.CId)
                .HasComment("r,d-编号")
                .HasColumnName("c_id");
            entity.Property(e => e.CBusinessId)
                .HasComment("c,r-商家编号")
                .HasColumnName("c_business_id");
            entity.Property(e => e.CCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("c_create_time");
            entity.Property(e => e.CGoodId)
                .HasComment("c,r-商品编号")
                .HasColumnName("c_good_id");

            entity.HasOne(d => d.CBusiness).WithMany(p => p.Collections)
                .HasForeignKey(d => d.CBusinessId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("collections_ibfk_2");

            entity.HasOne(d => d.CGood).WithMany(p => p.Collections)
                .HasForeignKey(d => d.CGoodId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("collections_ibfk_1");
        });

        modelBuilder.Entity<Comment>(entity =>
        {
            entity.HasKey(e => e.CId).HasName("PRIMARY");

            entity.ToTable("comments", tb => tb.HasComment("评价表(不允许修改只能删除)"));

            entity.HasIndex(e => e.CAccountId, "c_account_id");

            entity.HasIndex(e => e.CCommentId, "c_comment_id");

            entity.HasIndex(e => e.CGoodId, "c_good_id");

            entity.HasIndex(e => e.CMainCommentId, "c_main_comment_id");

            entity.HasIndex(e => e.COrderDetailId, "c_order_detail_id").IsUnique();

            entity.Property(e => e.CId)
                .HasComment("r,u,d-编号")
                .HasColumnName("c_id");
            entity.Property(e => e.CAccountId)
                .HasComment("c,r-评价人")
                .HasColumnName("c_account_id");
            entity.Property(e => e.CCommentId)
                .HasComment("c,r-回复评论")
                .HasColumnName("c_comment_id");
            entity.Property(e => e.CContent)
                .HasMaxLength(400)
                .HasComment("c,r-评价内容")
                .HasColumnName("c_content");
            entity.Property(e => e.CCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("c_create_time");
            entity.Property(e => e.CGoodId)
                .HasComment("c,r-评价商品")
                .HasColumnName("c_good_id");
            entity.Property(e => e.CMainCommentId)
                .HasComment("c,r-主评论")
                .HasColumnName("c_main_comment_id");
            entity.Property(e => e.COrderDetailId)
                .HasComment("c,r-评价订单详情")
                .HasColumnName("c_order_detail_id");
            entity.Property(e => e.CRate)
                .HasComment("c,r-评分")
                .HasColumnName("c_rate");

            entity.HasOne(d => d.CAccount).WithMany(p => p.Comments)
                .HasForeignKey(d => d.CAccountId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("comments_ibfk_1");

            entity.HasOne(d => d.CComment).WithMany(p => p.InverseCComment)
                .HasForeignKey(d => d.CCommentId)
                .OnDelete(DeleteBehavior.Cascade)
                .HasConstraintName("comments_ibfk_4");

            entity.HasOne(d => d.CGood).WithMany(p => p.Comments)
                .HasForeignKey(d => d.CGoodId)
                .OnDelete(DeleteBehavior.Cascade)
                .HasConstraintName("comments_ibfk_2");

            entity.HasOne(d => d.CMainComment).WithMany(p => p.InverseCMainComment)
                .HasForeignKey(d => d.CMainCommentId)
                .OnDelete(DeleteBehavior.Cascade)
                .HasConstraintName("comments_ibfk_3");

            entity.HasOne(d => d.COrderDetail).WithOne(p => p.Comment)
                .HasForeignKey<Comment>(d => d.COrderDetailId)
                .HasConstraintName("comments_ibfk_5");
        });

        modelBuilder.Entity<CommentLike>(entity =>
        {
            entity.HasKey(e => e.ClId).HasName("PRIMARY");

            entity.ToTable("comment_likes", tb => tb.HasComment("点赞表"));

            entity.HasIndex(e => e.ClCommentId, "cl_comment_id");

            entity.Property(e => e.ClId)
                .HasComment("r,d-编号")
                .HasColumnName("cl_id");
            entity.Property(e => e.ClAccountId)
                .HasComment("c,r-引用账号")
                .HasColumnName("cl_account_id");
            entity.Property(e => e.ClCommentId)
                .HasComment("c,r-引用评价")
                .HasColumnName("cl_comment_id");

            entity.HasOne(d => d.ClComment).WithMany(p => p.CommentLikes)
                .HasForeignKey(d => d.ClCommentId)
                .HasConstraintName("comment_likes_ibfk_1");
        });

        modelBuilder.Entity<CommentResource>(entity =>
        {
            entity.HasKey(e => e.CrId).HasName("PRIMARY");

            entity.ToTable("comment_resources", tb => tb.HasComment("评价资源表"));

            entity.HasIndex(e => e.CrCommentId, "cr_comment_id");

            entity.Property(e => e.CrId)
                .HasComment("r,u,d-编号")
                .HasColumnName("cr_id");
            entity.Property(e => e.CrCommentId)
                .HasComment("c,r-引用评价")
                .HasColumnName("cr_comment_id");
            entity.Property(e => e.CrExtendName)
                .HasMaxLength(8)
                .HasComment("c,r-扩展名")
                .HasColumnName("cr_extend_name");
            entity.Property(e => e.CrFileName)
                .HasMaxLength(40)
                .HasComment("c,r-文件名")
                .HasColumnName("cr_file_name");
            entity.Property(e => e.CrPath)
                .HasMaxLength(256)
                .HasComment("c,r-完整路径")
                .HasColumnName("cr_path");

            entity.HasOne(d => d.CrComment).WithMany(p => p.CommentResources)
                .HasForeignKey(d => d.CrCommentId)
                .HasConstraintName("comment_resources_ibfk_1");
        });

        modelBuilder.Entity<Dictionary>(entity =>
        {
            entity.HasKey(e => e.DId).HasName("PRIMARY");

            entity.ToTable("dictionarys", tb => tb.HasComment("字典表"));

            entity.HasIndex(e => e.DDictionaryTypeId, "d_dictionary_type_id");

            entity.HasIndex(e => e.DParentId, "d_parent_id");

            entity.Property(e => e.DId)
                .HasComment("r,u,d-编号")
                .HasColumnName("d_id");
            entity.Property(e => e.DCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("d_create_time");
            entity.Property(e => e.DDictionaryTypeId)
                .HasComment("c,r-字典类别")
                .HasColumnName("d_dictionary_type_id");
            entity.Property(e => e.DParentId)
                .HasComment("c,r-父级节点")
                .HasColumnName("d_parent_id");
            entity.Property(e => e.DUpdateTime)
                .ValueGeneratedOnAddOrUpdate()
                .HasComment("r-修改时间")
                .HasColumnType("datetime")
                .HasColumnName("d_update_time");
            entity.Property(e => e.DValue)
                .HasMaxLength(256)
                .HasComment("c,r,u-值")
                .HasColumnName("d_value");

            entity.HasOne(d => d.DDictionaryType).WithMany(p => p.Dictionaries)
                .HasForeignKey(d => d.DDictionaryTypeId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("dictionarys_ibfk_1");

            entity.HasOne(d => d.DParent).WithMany(p => p.InverseDParent)
                .HasForeignKey(d => d.DParentId)
                .HasConstraintName("dictionarys_ibfk_2");
        });

        modelBuilder.Entity<DictionaryType>(entity =>
        {
            entity.HasKey(e => e.DtId).HasName("PRIMARY");

            entity.ToTable("dictionary_types", tb => tb.HasComment("字典类别表"));

            entity.HasIndex(e => e.DtKey, "dt_key").IsUnique();

            entity.Property(e => e.DtId)
                .HasComment("r,u,d-编号")
                .HasColumnName("dt_id");
            entity.Property(e => e.DtCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("dt_create_time");
            entity.Property(e => e.DtDescription)
                .HasMaxLength(400)
                .HasComment("c,r,u-描述")
                .HasColumnName("dt_description");
            entity.Property(e => e.DtKey)
                .HasMaxLength(256)
                .HasComment("c,r,u-查询键值")
                .HasColumnName("dt_key");
            entity.Property(e => e.DtName)
                .HasMaxLength(256)
                .HasComment("c,r,u,k-名称")
                .HasColumnName("dt_name");
            entity.Property(e => e.DtUpdateTime)
                .ValueGeneratedOnAddOrUpdate()
                .HasComment("r-修改时间")
                .HasColumnType("datetime")
                .HasColumnName("dt_update_time");
        });

        modelBuilder.Entity<ErrorLog>(entity =>
        {
            entity.HasKey(e => e.ElId).HasName("PRIMARY");

            entity.ToTable("error_logs", tb => tb.HasComment("错误日志主表"));

            entity.Property(e => e.ElId)
                .HasComment("r,u,d-编号")
                .HasColumnName("el_id");
            entity.Property(e => e.ElCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("el_create_time");
            entity.Property(e => e.ElErrorTime)
                .HasComment("r-报错时间")
                .HasColumnType("datetime")
                .HasColumnName("el_error_time");
            entity.Property(e => e.ElMessage)
                .HasMaxLength(200)
                .HasComment("r-错误消息")
                .HasColumnName("el_message");
            entity.Property(e => e.ElParams)
                .HasComment("r-参数json")
                .HasColumnType("text")
                .HasColumnName("el_params");
            entity.Property(e => e.ElStackTrack)
                .HasComment("r-堆栈跟踪")
                .HasColumnType("text")
                .HasColumnName("el_stack_track");
            entity.Property(e => e.ElUrl)
                .HasMaxLength(200)
                .HasComment("r-请求地址")
                .HasColumnName("el_url");
        });

        modelBuilder.Entity<Good>(entity =>
        {
            entity.HasKey(e => e.GId).HasName("PRIMARY");

            entity.ToTable("goods", tb => tb.HasComment("商品表"));

            entity.HasIndex(e => e.GGoodTypeId, "g_good_type_id");

            entity.HasIndex(e => e.GSupplierId, "g_supplier_id");

            entity.HasIndex(e => new { e.GTopLevel, e.GId }, "idx_top_level_create_time").IsDescending();

            entity.Property(e => e.GId)
                .HasComment("r,u,d-编号")
                .HasColumnName("g_id");
            entity.Property(e => e.GBirthday)
                .HasComment("c,r,u-生产日期")
                .HasColumnType("datetime")
                .HasColumnName("g_birthday");
            entity.Property(e => e.GCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("g_create_time");
            entity.Property(e => e.GDescription)
                .HasMaxLength(2000)
                .HasComment("c,r,u-产品描述")
                .HasColumnName("g_description");
            entity.Property(e => e.GDetailImages)
                .HasMaxLength(820)
                .HasComment("c,r,u-详情图片")
                .HasColumnName("g_detail_images");
            entity.Property(e => e.GExpiryday)
                .HasComment("c,r,u-保质期")
                .HasColumnName("g_expiryday");
            entity.Property(e => e.GGoodTypeId)
                .HasComment("c,r-商品类别（引用dictionarys）")
                .HasColumnName("g_good_type_id");
            entity.Property(e => e.GInventory)
                .HasComment("r,u-库存")
                .HasColumnName("g_inventory");
            entity.Property(e => e.GIsDirectly)
                .HasComment("c,r,u-是否直营")
                .HasColumnName("g_is_directly");
            entity.Property(e => e.GIsPromote)
                .HasComment("r,u-是否促销(废弃)")
                .HasColumnName("g_is_promote");
            entity.Property(e => e.GIsShelve)
                .HasComment("r,u-是否上架")
                .HasColumnName("g_is_shelve");
            entity.Property(e => e.GName)
                .HasMaxLength(32)
                .HasComment("c,r,u,k-商品名称")
                .HasColumnName("g_name");
            entity.Property(e => e.GPhoto)
                .HasMaxLength(42)
                .HasComment("c,r,u-封面图片")
                .HasColumnName("g_photo");
            entity.Property(e => e.GPrice)
                .HasPrecision(12, 2)
                .HasComment("c,r,u-商品价格")
                .HasColumnName("g_price");
            entity.Property(e => e.GSpecs)
                .HasMaxLength(256)
                .HasComment("c,r,u-商品规格")
                .HasColumnName("g_specs");
            entity.Property(e => e.GSupplierId)
                .HasComment("c,r-供应商(引用suppliers)")
                .HasColumnName("g_supplier_id");
            entity.Property(e => e.GTopLevel)
                .HasComment("r,u-置顶级别（越大的排在越前面）")
                .HasColumnName("g_top_level");
            entity.Property(e => e.GUpdateTime)
                .ValueGeneratedOnAddOrUpdate()
                .HasComment("r-修改时间")
                .HasColumnType("datetime")
                .HasColumnName("g_update_time");

            entity.HasOne(d => d.GGoodType).WithMany(p => p.Goods)
                .HasForeignKey(d => d.GGoodTypeId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("goods_ibfk_1");

            entity.HasOne(d => d.GSupplier).WithMany(p => p.Goods)
                .HasForeignKey(d => d.GSupplierId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("goods_ibfk_2");
        });

        modelBuilder.Entity<History>(entity =>
        {
            entity.HasKey(e => e.HId).HasName("PRIMARY");

            entity.ToTable("historys", tb => tb.HasComment("历史记录表"));

            entity.HasIndex(e => e.HBusinessId, "h_business_id");

            entity.HasIndex(e => e.HGoodId, "h_good_id");

            entity.Property(e => e.HId)
                .HasComment("r,d-编号")
                .HasColumnName("h_id");
            entity.Property(e => e.HBusinessId)
                .HasComment("c,r-商家编号")
                .HasColumnName("h_business_id");
            entity.Property(e => e.HCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("h_create_time");
            entity.Property(e => e.HGoodId)
                .HasComment("c,r-商品编号")
                .HasColumnName("h_good_id");
            entity.Property(e => e.HVisitTime)
                .HasComment("c,r,u-浏览时间")
                .HasColumnType("datetime")
                .HasColumnName("h_visit_time");

            entity.HasOne(d => d.HBusiness).WithMany(p => p.Histories)
                .HasForeignKey(d => d.HBusinessId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("historys_ibfk_2");

            entity.HasOne(d => d.HGood).WithMany(p => p.Histories)
                .HasForeignKey(d => d.HGoodId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("historys_ibfk_1");
        });

        modelBuilder.Entity<Info>(entity =>
        {
            entity.HasKey(e => e.IId).HasName("PRIMARY");

            entity.ToTable("infos", tb => tb.HasComment("消息表"));

            entity.HasIndex(e => e.IReceiveMan, "i_receive_man");

            entity.HasIndex(e => e.ISendMan, "i_send_man");

            entity.Property(e => e.IId)
                .HasComment("r,u,d-编号")
                .HasColumnName("i_id");
            entity.Property(e => e.IContent)
                .HasMaxLength(1000)
                .HasComment("c,r-内容")
                .HasColumnName("i_content");
            entity.Property(e => e.ICreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("i_create_time");
            entity.Property(e => e.IIsRead)
                .HasComment("c,r-是否已读")
                .HasColumnName("i_is_read");
            entity.Property(e => e.IReceiveMan)
                .HasComment("c,r-接受人")
                .HasColumnName("i_receive_man");
            entity.Property(e => e.ISendMan)
                .HasComment("c,r-发送人")
                .HasColumnName("i_send_man");

            entity.HasOne(d => d.IReceiveManNavigation).WithMany(p => p.InfoIReceiveManNavigations)
                .HasForeignKey(d => d.IReceiveMan)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("infos_ibfk_2");

            entity.HasOne(d => d.ISendManNavigation).WithMany(p => p.InfoISendManNavigations)
                .HasForeignKey(d => d.ISendMan)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("infos_ibfk_1");
        });

        modelBuilder.Entity<LoginLog>(entity =>
        {
            entity.HasKey(e => e.LlId).HasName("PRIMARY");

            entity.ToTable("login_logs", tb => tb.HasComment("登录日志表"));

            entity.HasIndex(e => e.LlAccountId, "ll_account_id");

            entity.Property(e => e.LlId)
                .HasComment("r,u,d-编号")
                .HasColumnName("ll_id");
            entity.Property(e => e.LlAccountId)
                .HasComment("r-登录的管理员")
                .HasColumnName("ll_account_id");
            entity.Property(e => e.LlCode)
                .HasMaxLength(32)
                .HasComment("r-登录码")
                .HasColumnName("ll_code");
            entity.Property(e => e.LlCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("ll_create_time");
            entity.Property(e => e.LlIp)
                .HasMaxLength(20)
                .HasComment("r-登录地的IP地址")
                .HasColumnName("ll_ip");
            entity.Property(e => e.LlWay)
                .HasMaxLength(32)
                .HasComment("r-登录方式")
                .HasColumnName("ll_way");

            entity.HasOne(d => d.LlAccount).WithMany(p => p.LoginLogs)
                .HasForeignKey(d => d.LlAccountId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("login_logs_ibfk_1");
        });

        modelBuilder.Entity<Order>(entity =>
        {
            entity.HasKey(e => e.OId).HasName("PRIMARY");

            entity.ToTable("orders", tb => tb.HasComment("订单表"));

            entity.HasIndex(e => e.OBusinessId, "o_business_id");

            entity.HasIndex(e => e.OSupplierId, "o_supplier_id");

            entity.Property(e => e.OId)
                .HasComment("r,u,d-编号")
                .HasColumnName("o_id");
            entity.Property(e => e.OAcceptOrderTime)
                .HasComment("r,u-接单时间")
                .HasColumnType("datetime")
                .HasColumnName("o_accept_order_time");
            entity.Property(e => e.OBusinessId)
                .HasComment("c,r,u-商家（引用business）")
                .HasColumnName("o_business_id");
            entity.Property(e => e.OBusinessMarkup)
                .HasMaxLength(1000)
                .HasComment("r,u-商家备注")
                .HasColumnName("o_business_markup");
            entity.Property(e => e.OCompleteTime)
                .HasComment("r,u-完成时间")
                .HasColumnType("datetime")
                .HasColumnName("o_complete_time");
            entity.Property(e => e.OCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("o_create_time");
            entity.Property(e => e.OOrderId)
                .HasMaxLength(20)
                .HasComment("r-订单编号")
                .HasColumnName("o_order_id");
            entity.Property(e => e.OPayMoney)
                .HasPrecision(16, 2)
                .HasComment("r,u-实付金额")
                .HasColumnName("o_pay_money");
            entity.Property(e => e.ORefuseTime)
                .HasComment("r,u-拒绝时间(所有负数状态都视为拒绝)")
                .HasColumnType("datetime")
                .HasColumnName("o_refuse_time");
            entity.Property(e => e.OSendTime)
                .HasComment("r,u-发货时间")
                .HasColumnType("datetime")
                .HasColumnName("o_send_time");
            entity.Property(e => e.OShouldPayMoney)
                .HasPrecision(16, 2)
                .HasComment("r,u-应付金额")
                .HasColumnName("o_should_pay_money");
            entity.Property(e => e.OStatus)
                .HasComment("c,r,u-订单状态(0:未接单,1:待发货,2:已发货,3:全部完成,4:部分完成,-1:供应商拒绝接单(当前状态为未接单),-2:商家取消(当前状态为未发货或未接单),-3:供应商取消(当前状态为未发货)),-4:已拒收(当前状态为已发货)")
                .HasColumnName("o_status");
            entity.Property(e => e.OSupplierId)
                .HasComment("c,r,u-供应商（引用suppliers）")
                .HasColumnName("o_supplier_id");
            entity.Property(e => e.OSupplierMarkup)
                .HasMaxLength(1000)
                .HasComment("r,u-供应商备注")
                .HasColumnName("o_supplier_markup");

            entity.HasOne(d => d.OBusiness).WithMany(p => p.Orders)
                .HasForeignKey(d => d.OBusinessId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("orders_ibfk_1");

            entity.HasOne(d => d.OSupplier).WithMany(p => p.Orders)
                .HasForeignKey(d => d.OSupplierId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("orders_ibfk_2");
        });

        modelBuilder.Entity<OrderDetail>(entity =>
        {
            entity.HasKey(e => e.OdId).HasName("PRIMARY");

            entity.ToTable("order_details", tb => tb.HasComment("订单详情表"));

            entity.HasIndex(e => e.OdGoodId, "od_good_id");

            entity.HasIndex(e => e.OdGoodTypeId, "od_good_type_id");

            entity.HasIndex(e => e.OdOrderId, "od_order_id");

            entity.HasIndex(e => e.OdSupplierId, "od_supplier_id");

            entity.Property(e => e.OdId)
                .HasComment("r,u,d-编号")
                .HasColumnName("od_id");
            entity.Property(e => e.OdBirthday)
                .HasComment("c,r,u-生产日期")
                .HasColumnType("datetime")
                .HasColumnName("od_birthday");
            entity.Property(e => e.OdCount)
                .HasDefaultValueSql("'1'")
                .HasComment("c,r,u-原本的数量")
                .HasColumnName("od_count");
            entity.Property(e => e.OdDescription)
                .HasMaxLength(2000)
                .HasComment("c,r,u-产品描述")
                .HasColumnName("od_description");
            entity.Property(e => e.OdExpiryday)
                .HasComment("c,r,u-保质期")
                .HasColumnName("od_expiryday");
            entity.Property(e => e.OdGoodId)
                .HasComment("c,r-商品（引用goods)")
                .HasColumnName("od_good_id");
            entity.Property(e => e.OdGoodTypeId)
                .HasComment("c,r-商品类别（引用dictionarys）")
                .HasColumnName("od_good_type_id");
            entity.Property(e => e.OdIsDirectly)
                .HasComment("c,r,u-是否直营")
                .HasColumnName("od_is_directly");
            entity.Property(e => e.OdIsPromote)
                .HasComment("c,r,u-是否促销")
                .HasColumnName("od_is_promote");
            entity.Property(e => e.OdMoney)
                .HasPrecision(16, 2)
                .HasComment("c,r,u-原本的总价")
                .HasColumnName("od_money");
            entity.Property(e => e.OdName)
                .HasMaxLength(32)
                .HasComment("c,r,u,k-商品名称")
                .HasColumnName("od_name");
            entity.Property(e => e.OdOrderId)
                .HasComment("c,r-订单（引用orders）")
                .HasColumnName("od_order_id");
            entity.Property(e => e.OdPhoto)
                .HasMaxLength(42)
                .HasComment("c,r,u-封面图片")
                .HasColumnName("od_photo");
            entity.Property(e => e.OdPrice)
                .HasPrecision(12, 2)
                .HasComment("c,r,u-商品价格")
                .HasColumnName("od_price");
            entity.Property(e => e.OdPromotePrice)
                .HasPrecision(12, 2)
                .HasComment("c,r,u-促销价格")
                .HasColumnName("od_promote_price");
            entity.Property(e => e.OdReceivedCount)
                .HasComment("c,r,u-接收的数量")
                .HasColumnName("od_received_count");
            entity.Property(e => e.OdReceivedMoney)
                .HasPrecision(16, 2)
                .HasComment("c,r,u-接受的总价")
                .HasColumnName("od_received_money");
            entity.Property(e => e.OdSpecs)
                .HasMaxLength(256)
                .HasComment("c,r,u-商品规格")
                .HasColumnName("od_specs");
            entity.Property(e => e.OdSupplierId)
                .HasComment("c,r-供应商(引用suppliers)")
                .HasColumnName("od_supplier_id");

            entity.HasOne(d => d.OdGood).WithMany(p => p.OrderDetails)
                .HasForeignKey(d => d.OdGoodId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("order_details_ibfk_1");

            entity.HasOne(d => d.OdGoodType).WithMany(p => p.OrderDetails)
                .HasForeignKey(d => d.OdGoodTypeId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("order_details_ibfk_3");

            entity.HasOne(d => d.OdOrder).WithMany(p => p.OrderDetails)
                .HasForeignKey(d => d.OdOrderId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("order_details_ibfk_4");

            entity.HasOne(d => d.OdSupplier).WithMany(p => p.OrderDetails)
                .HasForeignKey(d => d.OdSupplierId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("order_details_ibfk_2");
        });

        modelBuilder.Entity<Promotion>(entity =>
        {
            entity.HasKey(e => e.PId).HasName("PRIMARY");

            entity.ToTable("promotions", tb => tb.HasComment("优惠活动表"));

            entity.HasIndex(e => e.PGoodId, "p_good_id");

            entity.HasIndex(e => e.PSupplierId, "p_supplier_id");

            entity.Property(e => e.PId)
                .HasComment("r,u,d-编号")
                .HasColumnName("p_id");
            entity.Property(e => e.PCreateAt)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("p_create_at");
            entity.Property(e => e.PDiscountPrice)
                .HasPrecision(12, 2)
                .HasComment("c,r,u-活动价")
                .HasColumnName("p_discount_price");
            entity.Property(e => e.PEndTime)
                .HasComment("c,r,u-结束时间")
                .HasColumnType("datetime")
                .HasColumnName("p_end_time");
            entity.Property(e => e.PGoodId)
                .HasComment("c,r-活动商品（引用商品表）")
                .HasColumnName("p_good_id");
            entity.Property(e => e.PStartTime)
                .HasComment("c,r,u-开始时间")
                .HasColumnType("datetime")
                .HasColumnName("p_start_time");
            entity.Property(e => e.PSupplierId)
                .HasComment("r-发布人（引用供应商表）")
                .HasColumnName("p_supplier_id");
            entity.Property(e => e.PUpdateAt)
                .ValueGeneratedOnAddOrUpdate()
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("r-修改时间")
                .HasColumnType("datetime")
                .HasColumnName("p_update_at");

            entity.HasOne(d => d.PGood).WithMany(p => p.Promotions)
                .HasForeignKey(d => d.PGoodId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("promotions_ibfk_2");

            entity.HasOne(d => d.PSupplier).WithMany(p => p.Promotions)
                .HasForeignKey(d => d.PSupplierId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("promotions_ibfk_1");
        });

        modelBuilder.Entity<SearchRecord>(entity =>
        {
            entity.HasKey(e => e.SrId).HasName("PRIMARY");

            entity.ToTable("search_records", tb => tb.HasComment("搜素记录表"));

            entity.Property(e => e.SrId)
                .HasComment("r,d-编号")
                .HasColumnName("sr_id");
            entity.Property(e => e.SrBusinessId)
                .HasComment("c,r-商家编号")
                .HasColumnName("sr_business_id");
            entity.Property(e => e.SrCreateTime)
                .HasComment("c,r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("sr_create_time");
            entity.Property(e => e.SrSearchTime)
                .HasComment("c,r-搜素时间")
                .HasColumnType("datetime")
                .HasColumnName("sr_search_time");
            entity.Property(e => e.SrSearchWord)
                .HasMaxLength(256)
                .HasComment("c,r-搜索词")
                .HasColumnName("sr_search_word");
        });

        modelBuilder.Entity<Supplier>(entity =>
        {
            entity.HasKey(e => e.SId).HasName("PRIMARY");

            entity.ToTable("suppliers", tb => tb.HasComment("供应商表"));

            entity.HasIndex(e => e.SAccountId, "s_account_id");

            entity.HasIndex(e => e.SShopName, "s_shop_name").IsUnique();

            entity.HasIndex(e => e.SType, "s_type");

            entity.Property(e => e.SId)
                .HasComment("r,u,d-编号")
                .HasColumnName("s_id");
            entity.Property(e => e.SAccountId)
                .HasComment("r,u-账号编号")
                .HasColumnName("s_account_id");
            entity.Property(e => e.SAddress)
                .HasMaxLength(256)
                .HasComment("c,r,u-供应商地址")
                .HasColumnName("s_address");
            entity.Property(e => e.SAnnouncement)
                .HasMaxLength(256)
                .HasComment("c,r,u-供应商公告")
                .HasColumnName("s_announcement");
            entity.Property(e => e.SCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("s_create_time");
            entity.Property(e => e.SEnterpriseName)
                .HasMaxLength(100)
                .HasComment("c,r,u-企业名称")
                .HasColumnName("s_enterprise_name");
            entity.Property(e => e.SLogo)
                .HasMaxLength(42)
                .HasComment("c,r,u-企业logo")
                .HasColumnName("s_logo");
            entity.Property(e => e.SOpenId)
                .HasMaxLength(50)
                .HasComment("c,r,u-微信ID")
                .HasColumnName("s_open_id");
            entity.Property(e => e.SPhoto)
                .HasMaxLength(840)
                .HasComment("c,r,u-企业图片(最多20张)")
                .HasColumnName("s_photo");
            entity.Property(e => e.SQualification)
                .HasMaxLength(840)
                .HasComment("c,r,u-企业资质(最多20张)")
                .HasColumnName("s_qualification");
            entity.Property(e => e.SShopName)
                .HasMaxLength(32)
                .HasComment("c,r,u-店铺名称")
                .HasColumnName("s_shop_name");
            entity.Property(e => e.SType)
                .HasComment("c,r,u-经营类别,引用字典表")
                .HasColumnName("s_type");
            entity.Property(e => e.SUpdateTime)
                .ValueGeneratedOnAddOrUpdate()
                .HasComment("r-修改时间")
                .HasColumnType("datetime")
                .HasColumnName("s_update_time");

            entity.HasOne(d => d.SAccount).WithMany(p => p.Suppliers)
                .HasForeignKey(d => d.SAccountId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("suppliers_ibfk_1");

            entity.HasOne(d => d.STypeNavigation).WithMany(p => p.Suppliers)
                .HasForeignKey(d => d.SType)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("suppliers_ibfk_2");
        });

        modelBuilder.Entity<Varify>(entity =>
        {
            entity.HasKey(e => e.VId).HasName("PRIMARY");

            entity.ToTable("varifys", tb => tb.HasComment("验证码表"));

            entity.Property(e => e.VId)
                .HasComment("r,u,d-编号")
                .HasColumnName("v_id");
            entity.Property(e => e.VCode)
                .HasMaxLength(6)
                .HasComment("r-验证码")
                .HasColumnName("v_code");
            entity.Property(e => e.VCreateTime)
                .HasDefaultValueSql("now()")
                .HasComment("r-创建时间")
                .HasColumnType("datetime")
                .HasColumnName("v_create_time");
            entity.Property(e => e.VIsUsed)
                .HasComment("r,u-是否使用")
                .HasColumnName("v_is_used");
            entity.Property(e => e.VOutTime)
                .HasComment("r-过期时间")
                .HasColumnType("datetime")
                .HasColumnName("v_out_time");
            entity.Property(e => e.VPhone)
                .HasMaxLength(11)
                .HasComment("c,r-手机号")
                .HasColumnName("v_phone");
            entity.Property(e => e.VUpdateTime)
                .ValueGeneratedOnAddOrUpdate()
                .HasComment("r-修改时间")
                .HasColumnType("datetime")
                .HasColumnName("v_update_time");
            entity.Property(e => e.VUseTime)
                .HasComment("r,u-使用时间")
                .HasColumnType("datetime")
                .HasColumnName("v_use_time");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
